# coding=utf-8

from selenium.webdriver.common.by import By
from PageObject.base_page import BasePage


class ContactPage(BasePage):
    """
    企业微信“通讯录”页面PO类
    """
    # 通讯录页面URL
    _base_url = "https://work.weixin.qq.com/wework_admin/frame#contacts"

    # 元素定位
    _names_selector = (By.CSS_SELECTOR, "#member_list>tr>td:nth-child(2)")
    _add_member_selector = (By.CSS_SELECTOR, ".js_add_member")

    def get_member_name_list(self):
        """ 获取通讯录中成员的姓名
        :return: 返回一个包含成员姓名的列表
        """
        ele_list = self.finds(self._names_selector)
        name_list = [ele.text for ele in ele_list]

        return name_list

    def go_to_add_member(self):
        """ 跳转到添加成员页面
        :return: 返回一个AddMemberPage实例
        """
        self.find(self._add_member_selector)
        # 在此处导入AddMemberPage，避免循环导入错误
        from PageObject.add_member_page import AddMemberPage
        return AddMemberPage(self.driver)
